package com.itheima.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
 @Slf4j
 //@WebFilter("/*")//设置拦截路径/*代表拦截所有请求
public class DemoFilter implements Filter {
    //初始化方法，在web服务器启动时会触发一次
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
       log.info("init");
    }
    //销毁方法，在web服务器正常关闭时会触发一次
    @Override
    public void destroy() {
        log.info("destroy");
    }
    //每次拦截到请求会触发，会调用多次
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("doFilter");

        //放行
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
